<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This page shows all resources available in a folder in the File Browser.
-->
<html>
<head>
	<title>Resources</title>
	<link href="browser.css" type="text/css" rel="stylesheet">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">

var oListManager = new Object() ;

oListManager.Clear = function()
{
	document.body.innerHTML = '' ;
}

function ProtectPath(path)
{
	path = path.replace( /\\/g, '\\\\') ;
	path = path.replace( /'/g, '\\\'') ;
	return path ;
}

oListManager.GetFolderRowHtml = function( folderName, folderPath )
{
	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false;">' ;

	return 	'<div class="file" title="'+ folderName +'">' +
			'<div>' + sLink +
			'<img class="icon" alt="" src="images/folder_big.gif" border="0" width="48" height="48" ><\/a>' +
			'<\/div>' +
            '<br /><div class="filename">'+ sLink + folderName +'<\/a>' + '<\/div>' +
            '<\/div>';
}

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize ){

	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;
	var relLink = '<a href="'+ fileUrl +'" rel="lightbox">' ;

	// Get the file icon.
	var sIcon = oIcons.GetIcon( fileName ) ;

	/**
	 *	Get file extension and decide if thumb or icon should be displayed
	 */

		if( sIcon == 'gif' || sIcon == 'jpg' || sIcon == 'jpeg' || sIcon == 'png' ){
			var imgTag = '<img class="thumb" alt="" src="' + fileUrl + '" />' ;
		}
		else {
			var imgTag = '<img class="icon" alt="" src="images/icons/' + sIcon + '.gif" />';
		}

			return '<div class="file" title="'+ fileName +'">' +
			'<span class="fSize">' +
			'<nobr><img alt="' + sIcon + '" title="' + sIcon + '" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"> '
			+ fileSize +
			' kB</nobr><\/span>' +
			'<div class="thumbnail">' + sLink + imgTag +'<\/a>' +
			'<\/div>' +
            '<br /><div class="filename"><nobr>' + sLink + fileName +	'<\/a>' + '</nobr><\/div>' +
            '<\/div>' ;
}

function OpenFolder( folderPath )
{
	// Load the resources list for this folder.
	window.parent.frames['frmFolders'].LoadFolders( folderPath ) ;
}

function OpenFile( fileUrl )
{
/*
    //PATCH: Using CKEditors API we set the file in preview window.
 	funcNum = GetUrlParam('CKEditorFuncNum') ;
    window.top.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl.replace( '#', '%23' ));
    window.top.close() ;
    window.top.opener.focus() ;
*/
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

function LoadResources( resourceType, folderPath )
{
	oListManager.Clear() ;
	oConnector.ResourceType = resourceType ;
	oConnector.CurrentFolder = folderPath ;
	oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
}

function Refresh()
{
	LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
}

function GetFoldersAndFilesCallBack( fckXml )
{
	if ( oConnector.CheckError( fckXml ) != 0 )
		return ;

	// Get the current folder path.
	var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
	if ( oFolderNode == null )
	{
		alert( 'The server didn\'t reply with a proper XML data. Please check your configuration.' ) ;
		return ;
	}
	var sCurrentFolderPath	= oFolderNode.attributes.getNamedItem('path').value ;
	var sCurrentFolderUrl	= oFolderNode.attributes.getNamedItem('url').value ;

//	var dTimer = new Date() ;

	var oHtml = new StringBuilder( '<div id="tableFiles"><div>' ) ;

	// Add the Folders.
	var oNodes ;
	oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
	for ( var i = 0 ; i < oNodes.length ; i++ )
	{
		var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
		oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) ) ;
	}

	// Add the Files.
	oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
	for ( var j = 0 ; j < oNodes.length ; j++ )
	{
		var oNode = oNodes[j] ;
		var sFileName = oNode.attributes.getNamedItem('name').value ;
		var sFileSize = oNode.attributes.getNamedItem('size').value ;

		// Get the optional "url" attribute. If not available, build the url.
		var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url') ;
		var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : encodeURI( sCurrentFolderUrl + sFileName ).replace( /#/g, '%23' ) ;

		// hide index.php in browse media - added for WebsiteBaker
		if (sFileName != "index.php")
		{
			oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize ) ) ;
		}
	}

	oHtml.Append( '<\/div><\/div>' ) ;

	document.body.innerHTML = oHtml.ToString() ;

//	window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;

}

function GetUrlParam( paramName )
{
    var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
    var oMatch = oRegex.exec( window.top.location.search ) ;

    if ( oMatch && oMatch.length > 1 )
        return decodeURIComponent( oMatch[1] ) ;
    else
        return '' ;
}

window.onload = function()
{
	window.top.IsLoadedResourcesList = true ;
}
	</script></head>
<body class="FileArea">
</body>
</html>
